package com.thf.controller.product;

import com.alibaba.fastjson.JSON;
import com.thf.model.PageModel;
import com.thf.model.ResultData;
import com.thf.service.ProductService;
import com.thf.util.Tool;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;


@Controller
public class ProductFindAllController{
    @Resource
    private ProductService productService ;
    @RequestMapping("/back/product/findAll")
    @ResponseBody
    protected String productFindAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        req.setCharacterEncoding("UTF-8");
//        resp.setCharacterEncoding("UTF-8");
        ResultData result = null ;
        String startPage = req.getParameter("startPage");
        String pageSize = req.getParameter("pageSize");
        PageModel pageMode = new PageModel(Tool.curPageToInt(startPage), Tool.pageSizeToInt(pageSize));
        String val = req.getParameter("val");
        Map map = JSON.parseObject(val,Map.class);
        //System.out.println(map);
        result = productService.productFindAll(pageMode,map);

        //       反馈给前端--返回值
        String resJson = JSON.toJSONString(result);
        //System.out.println(resJson);
//        resp.getWriter().println(resJson);
        return resJson ;

    }
}
